// page/component/index/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
	  category: [
		  { name: '果味', id: 'guowei' },
		  { name: '蔬菜', id: 'shucai' },
		  { name: '炒货', id: 'chaohuo' },
		  { name: '点心', id: 'dianxin' },
		  { name: '粗茶', id: 'cucha' },
		  { name: '蔬菜', id: 'shucai' },
		  { name: '炒货', id: 'chaohuo' },
		  { name: '点心', id: 'dianxin' },
		  { name: '粗茶', id: 'cucha' },
		  { name: '蔬菜', id: 'shucai' },
		  { name: '炒货', id: 'chaohuo' },
		  { name: '点心', id: 'dianxin' },
		  { name: '粗茶', id: 'cucha' },
		  { name: '淡饭', id: 'danfan' }
	  ],
	  sideIndex:-1,		//侧边栏选中状态
	  goodsIndex:-1,	//商品的下标
	  goodsNum:[0,0,0],
	  listShow:false,	//商品列表的显示隐藏
	  totalShow:false	//显示合计
  },

  /**
   * 组件的方法列表
   */
  methods: {
	  clickSide:function(e){
		//   选中侧边栏
		  this.setData({
			  sideIndex:e.currentTarget.dataset.index
		  })
	  },
	  addShop:function(e){
		//   添加商品
		  let index = e.currentTarget.dataset.goods
		  let currentNum = ++this.data.goodsNum[index]
		  let goodsNum = 'goodsNum[' + index + ']'
		  this.setData({
			  [goodsNum]: currentNum,
			  totalShow:true
		  })
	  },
	  reduceShop: function (e) {
		  //   减少商品
		  let index = e.currentTarget.dataset.goods
		  let currentNum = --this.data.goodsNum[index]
		  if (currentNum<0){
			  currentNum=0
			  this.setData({
				  listShow:false
			  })
		  }
		  let goodsNum = 'goodsNum[' + index + ']'
		  this.setData({
			  [goodsNum]: currentNum
		  })
	  },
	  showList:function() {
		//   显示或切换购物列表的商品
		this.setData({
			listShow: !this.data.listShow
		})
	  },
	  clearGoods:function(){
		//   清空购物列表的商品
		  this.setData({
			  goodsNum:[],
			  listShow:false
		  })
	  },
	  order:function(){
		//   下单
		  wx.navigateTo({
			  url: './settlement/settlement'
		})
	  }
  }
})
